<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./node_modules/vue/dist/vue.js"></script>
</head>
<body>
    <div id="root">
        <!-- 这是一个动态组件
             它的is属性,绑定的是组件名字
        -->
        
        <component :is="type"></component>
        <!-- <child-one v-if="type==='one'"></child-one>
        <child-two v-if="type==='two'"></child-two>-->
        <button @click="handleBtnClick">change</button> 
    </div>
<!-- v-once可以有效提高静态内容的展示效率
     直接加在标签上就行
                
        -->
    <script>

        Vue.component(
            'child-one',
            {
            template:`<div v-once>childOne</div>`
            }
        )
        
        Vue.component(
            'child-two',
            {
            template:`<div v-once>childTwo</div>`
            }
        )
        
        
        var vm = new Vue({
            el:"#root",
            data:{
                type:'child-one'
            },
            methods:{
                handleBtnClick(){
                    this.type = (this.type==='child-one'? 'child-two':'child-one')
                }
            }

        })
    </script>
</body>
</html>